package com.example.redissondemo.controller;

import com.example.redissondemo.consumer.MessageEvent;
import com.example.redissondemo.consumer.TestEntityMessageListener;
import com.example.redissondemo.consumer.TestStringMessageListener;
import com.example.redissondemo.utils.DateUtil;
import com.example.redissondemo.utils.IdGenerator;
import com.example.redissondemo.utils.RedissonUtil;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 信息发送接口
 *
 * @author Liunh
 */
@Slf4j
@RestController
@RequestMapping(value = "/msg")
public class TestMsgController {

    @Resource
    private RedissonUtil redissonUtil;
    @Resource
    private TestEntityMessageListener entityMessageListener;
    @Resource
    private TestStringMessageListener stringMessageListener;

    @GetMapping("/sendMsg1")
    public String sendMsg1() {
        redissonUtil.sendMsg(RedissonUtil.REDIS_PRE_TOPIC_KEY + TestStringMessageListener.TOPIC_STRING_TEST, String.class,
                stringMessageListener, "test redisson send string msg1，datetime = " + DateUtil.getCurrentDate());
        return "rTopicTest1";
    }

    @GetMapping("/sendMsg")
    public String sendMsg() {
        MessageEvent event = new MessageEvent();
        event.setMsgNo(IdGenerator.getInstance().getUuid());
        event.setTitle("test send msg");
        event.setMsg("test redisson send entity msg，datetime = " + DateUtil.getCurrentDate());
        redissonUtil.sendMsg(RedissonUtil.REDIS_PRE_TOPIC_KEY + TestEntityMessageListener.TOPIC_ENTITY_TEST, MessageEvent.class,
                entityMessageListener, event);
        return "rTopicTest";
    }


}
